home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*----------------------------------------------------------------------------
- *
- * file : main.c for texVol (volume rendering with 2d or 3d textures)
- *
- * Author : Yusuf Attarwala
- * Date : Sep 93
- *
- *---------------------------------------------------------------------------*/
- #include <sys/types.h>
- #include <malloc.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <math.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- #define DEFINE_VOL_GLOBALS 1
- #include "globals_vol.h"
- #undef DEFINE_VOL_GLOBALS
- #include <Xm/Protocols.h>
- #include <X11/StringDefs.h>
-
- typedef struct _cmdLine {
- String modelName; /* model name */
- String textureMode; /* texture mode */
- } CmdLine, *CmdLinePtr;
-
- CmdLine commandLine;
-
- static XtResource resources[] = {
- {"modelName", "ModelName", XtRString, sizeof(String),
- XtOffset(CmdLinePtr,modelName), XtRString, "Untitled",},
- {"textureMode", "TextureMode",XtRString, sizeof(String),
- XtOffset(CmdLinePtr,textureMode), XtRString, "2"},
- };
-
- static XrmOptionDescRec options[] = {
- {"-f", "modelName", XrmoptionSepArg, NULL},
- {"-tex", "textureMode",XrmoptionSepArg, NULL},
- };
-
- static String fallbackResources[] = {
- "*background: grey",
- "*XmSeparator.traversalOn: False",
- "*XmLabel.traversalOn: False",
- "*fillOnSelect: True",
- "*selectColor: yellow",
- "*ui*fontList: -adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*",
- "*message*fontList: -adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*",
- "*gizmo*fontList: -adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*",
- NULL
- };
-
- /* function declaration */
- void main();
- void readAndInitData();
-
-
- void
- printDescription()
- {
- printf("\n Volume rendering using 2D Textures \n\n");
- printf(" This demo maintains three orthogonal sets of planes\n");
- printf(" on which 2d textures are mapped. Depending upon the\n");
- printf(" direction of view, one set is selected and the textures\n");
- printf(" from these planes are composited using blendfunction.\n\n");
- printf(" The data set is 128 x 128 x 64 slices of 8 bit data.\n");
- printf(" 2 component textures (alpha + intensity) are used for\n");
- printf(" this demo\n\n");
- printf(" Author : Yusuf Attarwala x 3-3342 (SGI - Applications)\n\n");
- printf(" Please refer to the following cheat sheet for keyboard\n");
- printf(" commands\n\n");
- }
- extern Boolean prepare2DTexture(),
- prepare3DTexture();
-
- void
- main(argc,argv)
- int argc;
- char **argv;
- {
- Atom xaWmDeleteWindow;
- void doExit();
-
- toplevel = XtAppInitialize(&appContext,"TexVol",
- options,XtNumber(options),
- &argc,argv,
- fallbackResources,
- (ArgList)NULL, 0);
-
-
- display = XtDisplay(toplevel);
- screen = XDefaultScreen(display);
- XtGetApplicationResources(toplevel,&commandLine,
- resources,XtNumber(resources),
- NULL,0);
-
-
- if (strcmp(commandLine.textureMode,"2") == 0) {
- textureMode = TEXTURE_2D;
- if (!getgdesc(GD_TEXTURE)) {
- printf("This machine does not support textures..., aborting\n");
- exit(0);
- }
- XtVaSetValues(toplevel,XmNtitle,"2D VolRender UI",
- XmNiconName,"TexVol",
- XmNdeleteResponse, XmDO_NOTHING,
- NULL);
-
- }
- else {
- textureMode = TEXTURE_3D;
- if (!getgdesc(GD_TEXTURE_3D)) {
- printf("This machine does not support 3d textures..., aborting\n");
- printf("Try running in 2d texture mode (default)\n");
- exit(0);
- }
- XtVaSetValues(toplevel,XmNtitle,"3D VolRender UI",
- XmNiconName,"TexVol",
- XmNdeleteResponse, XmDO_NOTHING,
- NULL);
-
- }
- xaWmDeleteWindow = XmInternAtom(display,"WM_DELETE_WINDOW",TRUE);
- XmAddWMProtocolCallback(toplevel,xaWmDeleteWindow,doExit,0);
-
-
-
- if (strcmp(commandLine.modelName,"Untitled") != 0) {
- readAndInitData(commandLine.modelName,128,128,64,0);
- }
- else {
- readAndInitData("clamped.bin",128,128,64,0);
- }
-
- initGlobals();
- createMenus(toplevel);
- computeBoundingBox();
- computeProjectionView();
- XtRealizeWidget(toplevel);
-
- createGraphics(toplevel);
- drawScene();
- XFlush(display);
-
- if (textureMode == TEXTURE_2D) {
- prepare2DTexture();
- }
- else {
- prepare3DTexture();
- }
- drawScene();
-
- XtAppMainLoop(appContext);
- }
-
- void
- doExit()
- {
- exit(0);
- }
-
-